home *** CD-ROM | disk | FTP | other *** search
/ PC Graphics Unleashed / PC Graphics Unleashed.iso / ch01 / vesainfo.c < prev    next >
Text File  |  1993-12-06  |  5KB  |  166 lines

  1. /**
  2.  ** VESAINFO.C ---- test program to print VESA BIOS information
  3.  **
  4.  ** Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  5.  ** Copyright (C) 1992 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
  6.  ** Copyright (C) 1993 Grzegorz Mazur, gbm@ii.pw.edu.pl
  7.  **
  8.  ** This file is distributed under the terms listed in the document
  9.  ** "copying.dj", available from DJ Delorie at the address above.
  10.  ** A copy of "copying.dj" should accompany this file; if not, a copy
  11.  ** should be available from where this file was obtained.  This file
  12.  ** may not be distributed without a verbatim copy of "copying.dj".
  13.  **
  14.  ** This file is distributed WITHOUT ANY WARRANTY; without even the implied
  15.  ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16.  **/
  17.  
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. #include <dos.h>
  21.  
  22. #include "pieces/vesainfo.c"
  23.  
  24. void printinfo(VgaInfoBlock *vgainfo)
  25. {
  26.     char  far *sp = vgainfo->OEMStringPtr;
  27.     short far *mp = vgainfo->VideoModePtr;
  28.  
  29.     printf("VESASignature:\t\"%c%c%c%c\"\n",
  30.         vgainfo->VESASignature[0],
  31.         vgainfo->VESASignature[1],
  32.         vgainfo->VESASignature[2],
  33.         vgainfo->VESASignature[3]
  34.     );
  35.     printf("VESAVersion:\t%d.%d\n",
  36.         VESA_VERSION_MAJOR(VESAversion),
  37.         VESA_VERSION_MINOR(VESAversion)
  38.     );
  39.     printf("OEMStringPtr:\t\"");
  40.     while(*sp != '\0') putchar(*sp++);
  41.     printf("\"\nCapabilities:\t%ld\n",vgainfo->Capabilities);
  42.     printf("VideoModePtr:\t%Fp\n",mp);
  43.     printf("Video Modes:\t");
  44.     while(*mp != (-1)) printf("0x%x ",*mp++);
  45.     printf("\n\n");
  46. }
  47.  
  48. #define DEFBIT(bit)    { bit, #bit }
  49. typedef struct {
  50.     int  bit;
  51.     char *name;
  52. } bitdef;
  53.  
  54. bitdef modeattrbits[] = {
  55.     DEFBIT(MODE_SUPPORTED),
  56.     DEFBIT(MODE_EXTINFO),
  57.     DEFBIT(MODE_SUPBIOS),
  58.     DEFBIT(MODE_ISCOLOR),
  59.     DEFBIT(MODE_ISGRAPHICS),
  60.     { 0 }
  61. };
  62.  
  63. bitdef winattrbits[] = {
  64.     DEFBIT(WIN_SUPPORTED),
  65.     DEFBIT(WIN_READABLE),
  66.     DEFBIT(WIN_WRITABLE),
  67.     { 0 }
  68. };
  69.  
  70. bitdef memorymodels[] = {
  71.     DEFBIT(MODEL_TEXT),
  72.     DEFBIT(MODEL_CGA),
  73.     DEFBIT(MODEL_HERC),
  74.     DEFBIT(MODEL_4PLANE),
  75.     DEFBIT(MODEL_PACKED),
  76.     DEFBIT(MODEL_256_NC),
  77.     DEFBIT(MODEL_DIRECT),
  78.     { 0 }
  79. };
  80.  
  81. void printbits(int value,bitdef *def)
  82. {
  83.     int prev = 0;
  84.  
  85.     while(def->bit != 0) {
  86.         if(value & def->bit) {
  87.         if(prev) printf(" | ");
  88.         printf(def->name);
  89.         prev = 1;
  90.         }
  91.         def++;
  92.     }
  93.     if(!prev) printf("0");
  94.     printf("\n");
  95. }
  96.  
  97. char *getmodelname(int model)
  98. {
  99.     static char temp[50];
  100.  
  101.     if(model < 0) return(sprintf(temp,"Invalid model [%d]",model),temp);
  102.     if(model <= MODEL_DIRECT) return(memorymodels[model].name);
  103.     if(model <= 15) return(sprintf(temp,"VESA model [0x%02x]",model),temp);
  104.     return(sprintf(temp,"OEM model [%0x2x]",model),temp);
  105. }
  106.  
  107. void printmodeinfo(int mode,ModeInfoBlock *modeinfo)
  108. {
  109.     printf("Mode 0x%x is supported\n",mode);
  110.     printf("  ModeAttributes:   ");
  111.     printbits(modeinfo->ModeAttributes,modeattrbits);
  112.     printf("  WinAAttributes:   ");
  113.     printbits(modeinfo->WinAAttributes,winattrbits);
  114.     printf("  WinBAttributes:   ");
  115.     printbits(modeinfo->WinBAttributes,winattrbits);
  116.     printf("  WinGranularity:   %d\n",modeinfo->WinGranularity);
  117.     printf("  WinSize:          %d\n",modeinfo->WinSize);
  118.     printf("  WinASegment:      0x%04x\n",modeinfo->WinASegment);
  119.     printf("  WinBSegment:      0x%04x\n",modeinfo->WinBSegment);
  120.     printf("  WinFuncPtr:       \%Fp\n",modeinfo->WinFuncPtr);
  121.     printf("  BytesPerScanLine: %d\n",modeinfo->BytesPerScanLine);
  122.     if(!(modeinfo->ModeAttributes & MODE_EXTINFO)) return;
  123.     printf("  XResolution:      %d\n",modeinfo->XResolution);
  124.     printf("  YResolution:      %d\n",modeinfo->YResolution);
  125.     printf("  XCharSize:        %d\n",modeinfo->XCharSize);
  126.     printf("  YCharSize:        %d\n",modeinfo->YCharSize);
  127.     printf("  NumberOfPlanes:   %d\n",modeinfo->NumberOfPlanes);
  128.     printf("  BitsPerPixel:     %d\n",modeinfo->BitsPerPixel);
  129.     printf("  NumberOfBanks:    %d\n",modeinfo->NumberOfBanks);
  130.     printf("  MemoryModel:      %d (%s)\n",modeinfo->MemoryModel,getmodelname(modeinfo->MemoryModel));
  131.     printf("  BankSize:         %d\n",modeinfo->BankSize);
  132.     printf("  NumImagePages     %d\n",modeinfo->NumImagePages);
  133.     if(VESAversion < VESA_VERSION(1,2)) return;
  134.     printf("  RedMaskSize:      %d\n",modeinfo->RedMaskSize);
  135.     printf("  RedMaskPos:       %d\n",modeinfo->RedMaskPos);
  136.     printf("  GreenMaskSize:    %d\n",modeinfo->GreenMaskSize);
  137.     printf("  GreenMaskPos:     %d\n",modeinfo->GreenMaskPos);
  138.     printf("  BlueMaskSize:     %d\n",modeinfo->BlueMaskSize);
  139.     printf("  BlueMaskPos:      %d\n",modeinfo->BlueMaskPos);
  140.     printf("  ReservedMaskSize: %d\n",modeinfo->ReservedMaskSize);
  141.     printf("  ReservedMaskPos:  %d\n",modeinfo->ReservedMaskPos);
  142.     printf("  DirectScreenMode: %d\n",modeinfo->DirectScreenMode);
  143. }
  144.  
  145. void main(void)
  146. {
  147.     VgaInfoBlock  *vb;
  148.     ModeInfoBlock *mb;
  149.     if((vb = VESAgetInfo()) != NULL) {
  150.         static short modes[1000];
  151.         short far *modeptr = vb->VideoModePtr;
  152.         short *mdp = modes;
  153.         int mode;
  154.         printinfo(vb);
  155.         while((*mdp++ = *modeptr++) != (-1)) ;
  156.         mdp = modes;
  157.         while((mode = *mdp++) != (-1)) {
  158.         if((mb = VESAgetModeInfo(mode)) != NULL) printmodeinfo(mode,mb);
  159.         else printf("Mode 0x%x IS NOT SUPPORTED!\n",mode);
  160.         }
  161.     }
  162.     else printf("VESA BIOS extensions not found\n");
  163.     exit(0);
  164. }
  165.  
  166.